package com.sm.honkon.ui.adapter

import android.widget.ImageView
import android.widget.TextView
import androidx.core.view.isVisible
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.sm.honkon.R
import com.sm.honkon.data.bean.CalibrationBean

class CalibrationAdapter(
    data: MutableList<CalibrationBean> = arrayListOf(),
    layoutResIdRes: Int = R.layout.item_more_calibration
) :
    BaseQuickAdapter<CalibrationBean, BaseViewHolder>(layoutResIdRes, data) {

    var selectPosition = -1
        set(value) {
            if (field == value) {
                return
            }
            field = value
            notifyDataSetChanged()
        }
    var selectTestPosition = -1
        set(value) {
            if (field == value) {
                field = -1
            } else
                field = value
            notifyDataSetChanged()
        }

    override fun convert(helper: BaseViewHolder, item: CalibrationBean) {
        item.let {
            helper.apply {
                getView<TextView>(R.id.tv_mJ).text = "${it.mJ}MJ"
                getView<TextView>(R.id.tv_v).text = "${it.vol}V"
                getView<TextView>(R.id.tv_jiaozhun).let {
                    it.isSelected = layoutPosition == selectPosition
                    getView<ImageView>(R.id.iv_reduce).isVisible = it.isSelected
                    getView<ImageView>(R.id.iv_add).isVisible = it.isSelected
                }
                getView<TextView>(R.id.tv_test).isSelected = layoutPosition == selectTestPosition
            }
        }
    }

}